<template>
  <div class="home">
    <div class="hero-section">
      <h1>区块链商品溯源系统</h1>
      <h3>基于FISCO BCOS的安全透明溯源平台</h3>
    </div>
    
    <div class="features-section">
      <h2>核心功能</h2>
      
      <el-row :gutter="20" class="feature-row">
        <el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
          <el-card shadow="hover">
            <div slot="header">
              <i class="el-icon-box"></i>
              商品管理
            </div>
            <div>管理商品全生命周期，从创建、修改到销毁，确保数据真实可靠</div>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
          <el-card shadow="hover">
            <div slot="header">
              <i class="el-icon-sell"></i>
              所有权转移
            </div>
            <div>基于区块链的安全所有权转移系统，透明可信的商品交易记录</div>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
          <el-card shadow="hover">
            <div slot="header">
              <i class="el-icon-connection"></i>
              区块链交易
            </div>
            <div>全面的区块链交易可视化平台，实时区块链交易链路展示</div>
          </el-card>
        </el-col>
      </el-row>
    </div>
    
    <div class="dashboard-section">
      <el-card shadow="hover">
        <div slot="header">
          <i class="el-icon-monitor"></i> 系统状态
        </div>
        <div class="dashboard-content">
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
              <div class="status-block">
                <div class="status-title">区块链网络状态</div>
                <div class="status-value">
                  <el-tag :type="serverStatus && serverStatus.online ? 'success' : 'danger'">
                    <i :class="serverStatus && serverStatus.online ? 'el-icon-success' : 'el-icon-error'"></i>
                    {{ serverStatus && serverStatus.online ? '在线' : '离线' }}
                  </el-tag>
                </div>
              </div>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
              <div class="status-block">
                <div class="status-title">已选择账户</div>
                <div class="status-value">
                  <el-tag type="primary" v-if="selectedAccount">
                    <i class="el-icon-user"></i> {{ selectedAccount }}
                  </el-tag>
                  <el-tag type="info" v-else>
                    <i class="el-icon-warning"></i> 未选择账户
                  </el-tag>
                </div>
              </div>
            </el-col>
          </el-row>
          
          <div class="action-buttons">
            <el-button type="primary" @click="checkServerStatus">
              <i class="el-icon-refresh"></i> 刷新状态
            </el-button>
            <el-button type="success" @click="$router.push('/accounts')">
              <i class="el-icon-user"></i> 账户管理
            </el-button>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      serverStatus: null
    }
  },
  computed: {
    selectedAccount() {
      return this.$store.state.selectedAccount
    }
  },
  created() {
    // 初始化时加载账户信息
    this.$store.dispatch('fetchAccounts')
    this.checkServerStatus()
  },
  methods: {
    async checkServerStatus() {
      try {
        await this.$http.get('/api/goods/accounts')
        this.serverStatus = { online: true }
      } catch (error) {
        console.error('服务器连接失败:', error)
        this.serverStatus = { online: false }
      }
    }
  }
}
</script>

<style scoped>
.home {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
}

.hero-section {
  text-align: center;
  margin-bottom: 60px;
}

.hero-section h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-family: var(--font-heading);
}

.hero-section h3 {
  font-size: 1.2rem;
  margin-bottom: 2rem;
  color: var(--text-secondary);
  font-family: var(--font-main);
}

.features-section {
  margin-bottom: 60px;
}

.features-section h2 {
  font-size: 1.8rem;
  margin-bottom: 30px;
  color: var(--text-primary);
  font-family: var(--font-heading);
}

.feature-row {
  margin-top: 30px;
  margin-bottom: 30px;
}

.dashboard-section {
  margin-bottom: 30px;
}

.status-block {
  margin-bottom: 20px;
  text-align: center;
  padding: 15px;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: var(--border-radius);
}

.status-title {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.status-value {
  font-size: 1.2rem;
  font-weight: 600;
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: 20px;
}

@media (max-width: 768px) {
  .hero-section h1 {
    font-size: 2rem;
  }
  
  .hero-section h3 {
    font-size: 1.2rem;
  }
  
  .action-buttons {
    flex-direction: column;
  }
}
</style> 